package com.lxf.cn.rabbitmq;


import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Created by liaoxuefeng on 2018/12/3.
 */
//@Configuration
public class RabbitMQConfig {


    //  a  创建queue
    @Bean(name = "message") //  指定该参数名是message  见下面Qualifier（"message"）
    public Queue queueMessage(){
        return new Queue("topic.message");  //  topic.message  是rounting-key,匹配规则
    }

    @Bean(name = "notes")
    public Queue queueMessages(){
        return new Queue("topic.notes");
    }

    //  b. 创建交换机TopicExchange
    @Bean
    public TopicExchange exchange(){
        return new TopicExchange("topicExchange");
    }

    /*
      c. 根据绑定规则将队列绑定到相应的交换机上（bindingKey）--Exchange Queues

     */
    @Bean
    public Binding bindingExchangeMessage(@Qualifier("message") Queue queueMessage, TopicExchange exchange){
        return BindingBuilder.bind(queueMessage).to(exchange).with("topic.message");
    }

    @Bean
    /**
     * 将队列"messages" 绑定到交换机上，绑定规则是 topic.messages
     *
     */
    public  Binding bindingExchangeMessages(@Qualifier("notes")Queue queueMessages,TopicExchange exchange){
        return BindingBuilder.bind(queueMessages).to(exchange).with("topic.#");
    }

}
